Skip to content

fix(size): Stop named __cstring symbols from absorbing following literals - #759

Open
pcbeingused333 wants to merge 1 commit into
getsentry:mainfrom
pcbeingused333:fix/macho-cstring-symbol-size
Open

pcbeingused333 wants to merge 1 commit into
getsentry:mainfrom
pcbeingused333:fix/macho-cstring-symbol-size

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #678

Root cause. MachOSymbolSizes._symbol_sizes sizes a symbol as the distance to the next symbol in the same section (or to the section end). Literals in __TEXT,__cstring mostly have no symbol-table entry, so a named constant such as static const char hex[] = "0123456789abcdef"; was charged for every unnamed literal after it (17 bytes reported as ~78 KB in the issue).

Fix. For symbols in a C-string-literal section (TYPE.CSTRING_LITERALS), the end is clamped to the NUL terminator of the literal that starts at the symbol, still capped by the next symbol / section end. Other sections keep the existing heuristic. The unrelated literals are no longer attributed to the named symbol.

Test. New tests/unit/size/test_macho_symbol_sizes.py with a synthetic __cstring section: the named literal gets 17 bytes instead of the whole section (red before, green after), two named literals keep their own sizes, and a __text symbol is unchanged.

Not changed: the C Functions label for non-function symbols mentioned in the issue; that is a separate presentation change.

tests/integration/size has 9 failures that also fail identically on main in the environment used for this change (sizes/reference fixtures, strip, Android), so they are unrelated.

This change was prepared with the assistance of an AI coding agent (Claude).

…rals

In __cstring, literals are mostly unnamed, so the distance-to-next-symbol
heuristic charged every following literal to the preceding named constant
(e.g. a 17-byte hex lookup table reported as ~79 KB). Clamp the size of a
symbol in a C-string-literal section to its NUL terminator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: C-string symbol absorbs unrelated string data

1 participant